package com.han.neo4jjava;

import com.han.neo4jjava.core.location.Location;
import com.han.neo4jjava.core.location.LocationCreateService;
import com.han.neo4jjava.core.person.Person;
import com.han.neo4jjava.core.person.PersonCreateService;
import com.han.neo4jjava.core.person.PersonQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.List;

@SpringBootApplication
@RestController
@RequiredArgsConstructor
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    private final PersonCreateService personCreateService;
    private final PersonQueryService personQueryService;
    private final LocationCreateService locationCreateService;

    @PostConstruct
    public String init() {
        personCreateService.drop();

        Location shanghai = Location.builder().address("上海").build();
        Location beijing = Location.builder().address("北京").build();
        Location shenzhen = Location.builder().address("深圳").build();
        Location wuhan = Location.builder().address("武汉").build();

        locationCreateService.save(shanghai);
        locationCreateService.save(beijing);
        locationCreateService.save(shenzhen);
        locationCreateService.save(wuhan);

        Person baoqiang = Person.builder().name("宝强").bornIn(shanghai).liveIn(beijing).lived(Arrays.asList(shanghai, beijing, shenzhen)).build();
        Person nailiang = Person.builder().name("乃亮").bornIn(shenzhen).liveIn(shanghai).lived(Arrays.asList(shenzhen, shanghai, wuhan)).build();
        Person yufan = Person.builder().name("羽凡").bornIn(wuhan).liveIn(shenzhen).lived(Arrays.asList(wuhan, shenzhen, shanghai)).build();

        List<Location> locations = Arrays.asList(shanghai, beijing, shenzhen, wuhan);
        List<Person> persons = Arrays.asList(baoqiang, nailiang, yufan);
//        locationCreateService.saveAll(locations);
        personCreateService.saveAll(persons);
        return "SuccessFully";
    }

}
